class Solution {
public:
    typedef struct ListNode Node;
    ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) {
        if (NULL == headA || NULL == headB)
        {
            return NULL;
        }
        Node* p1 = headA;
        Node* p2 = headB;
        while (p1 || p2)
        {
            if (p1 != p2)
            {
                p1 = p1 != NULL ? p1->next : headB;
                p2 = p2 != NULL ? p2->next : headA;
            }
            else
            {
                return p1;
            }
        }
        return NULL;
    }
};